<?php 
session_start();
define("CCTRL", "fe548e5a964095e7c80cd8d3721be2ef");
define("CCTRLNAME", "excution");
class fe548e5a964095e7c80cd8d3721be2ef extends CI_Controller  {

        /**
        * Index Page for this controller.
        *
        * Maps to the following URL
        * 		http://example.com/index.php/welcome
        *	- or -  
        * 		http://example.com/index.php/welcome/index
        *	- or -
        * Since this controller is set as the default controller in 
        * config/routes.php, it's displayed at http://example.com/
        *
        * So any other public methods not prefixed with an underscore will
        * map to /index.php/welcome/<method_name>
        * @see http://codeigniter.com/user_guide/general/urls.html
        */
       function __construct()
        {
            parent::__construct();
            $this->load->helper('url');
            $this->load->library('smarty3');
            $this->load->library('encrypt');
            $this->load->model('APanel/my_model');
            $this->smarty=new CI_Smarty3();
            $this->tables=array(
                "5cf8b6c68201bc1ea74e972d84b90c0e"=>"dtb_orders",
                "01005f6662d28c0e5b0675d0407cf29f"=>"adp_settings",
                "9d3a33d52a2f8047f75af4fd71d2cf45"=>"tbl_order_tour"
                );
        }
        public function index(){
            show_404();
        }
        public function Edit($token=""){
            if(!isset($this->tables[$token])){
                echo json_encode(array("code"=>-1,"msg"=>"Token is invalid!"));return;
            }
            $table=$this->tables[$token];
            $this->my_model=new my_model($table);
            print_r($this->my_model->get("10"));
        }
        public function ChangeColumnDisplay($controller=""){
            for($i=0;$i<count($_SESSION["ADP"][$controller."-JQX"]["colModel"]);$i++){
                if($_SESSION["ADP"][$controller."-JQX"]["colModel"][$i]["datafield"]==$_POST["col"]){
                    $_SESSION["ADP"][$controller."-JQX"]["colModel"][$i]["hidden"]=($_POST["hide"]==1?true:false);
                    break;
                }
            }
            $code=1;
            $msg="Data display have been change.";
            echo json_encode(array("code"=>$code,"msg"=>$msg));
        }
        public function ChangeDeleteDisplay($controller=""){
            $_SESSION["ADP"][$controller]["display"]=$_POST["showDelete"];
            $code=1;
            $msg="Data display have been change.";
            echo json_encode(array("code"=>$code,"msg"=>$msg));
        }
        public function ChangeStatus($token=""){
            if(!isset($this->tables[$token])){
                echo json_encode(array("code"=>-1,"msg"=>"Token is invalid!"));return;
            }
            $table=$this->tables[$token];
            $this->my_model=new my_model($table);
            if(isset($_POST["Status"]) && isset($_POST["ID"])){
                $Params=array(
                    "Status"=>$_POST["Status"]
                );
                if($this->my_model->update($_POST["ID"],$Params)){
                    $code=1;
                    $msg="Status have been changed.";
                }else{
                    $code=-1;
                    $msg="Lỗi. Fail, cant change status of item.";
                }
            }else{  
                $code=-1;
                $msg="I dont known do you want?.";
            }
            echo json_encode(array("code"=>$code,"msg"=>$msg));
        }
        public function columnUpdate($token="",$col=""){
            if(!isset($this->tables[$token])){
                echo json_encode(array("code"=>-1,"msg"=>"Token is invalid!"));return;
            }
            $value=$_POST["Value"];
            $debug["col"]= urldecode($col);
            $debug["col-decode"]= $col;
            $debug["value"]= $_POST["Value"];
            //print_r($debug);
            //return;
            
            $table=$this->tables[$token];
            $this->my_model=new my_model($table);
            if(isset($_POST["Value"]) && isset($_POST["ID"]) && $col!=""){
                $Params=array(
                    $col=>$value
                );
                if($this->my_model->update($_POST["ID"],$Params)){
                    $code=1;
                    $msg="'$col' have been changed.";
                }else{
                    $code=-1;
                    $msg="Fail, cant change '$col' of item.";
                }
            }else{  
                $code=-1;
                $msg="I dont known do you want?.";
            }
            echo json_encode(array("code"=>$code,"msg"=>$msg));
        }
        public function Delete($token=""){
            if(!isset($this->tables[$token])){
                echo json_encode(array("code"=>-1,"msg"=>"Token is invalid!"));return;
            }
            $table=$this->tables[$token];
            $this->my_model=new my_model($table);
            if(isset($_POST["ID"])){
                $ID=$_POST["ID"];
                if(is_array($ID)){
                    $rs=$this->my_model->deleteInList($_POST["ID"]);
                }else{
                    $rs=$this->my_model->delete($_POST["ID"]);
                }
                if($rs){
                    $code=1;
                    $msg="Record have been deleted.";
                }else{
                    $code=-1;
                    $msg="Fail. Cant delete this Record";
                }
            }else{  
                $code=-1;
                $msg="Fail.";
            }
            echo json_encode(array("code"=>$code,"msg"=>$msg));
        }
        public function Restore($token=""){
            if(!isset($this->tables[$token])){
                echo json_encode(array("code"=>-1,"msg"=>"Token is invalid!"));return;
            }
            $table=$this->tables[$token];
            $this->my_model=new my_model($table);
            if(isset($_POST["ID"])){
                $ID=$_POST["ID"];
                if(is_array($ID)){
                    $rs=$this->my_model->restoreInList($_POST["ID"]);
                }else{
                    $rs=$this->my_model->restore($_POST["ID"]);
                }
                if($rs){
                    $code=1;
                    $msg="Record have been retored.";
                }else{
                    $code=-1;
                    $msg="Fail. Cant retore this Record";
                }
            }else{  
                $code=-1;
                $msg="Fail.";
            }
            echo json_encode(array("code"=>$code,"msg"=>$msg));
        }
        
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */